package fragmentson;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wq.cycling.R;

import activity.SonActivity;
import fragmentson.backhandle.BackHandledFragment;

import static com.wq.cycling.R.id.tv_next;


/**
 * 添加gps设备
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class AddGpsDevice extends BackHandledFragment {

	private View rootView;
	private ImageView iv_gpsdevice,iv_combo;
	private TextView tv_comboprice,tv_gpsprice,tv_allprice;
	private int comboprice = 10,gpsprice = 120;
	private View ll_linear5,ll_linear6,ll_linear7;
	private TextView tv_textview5,tv_textview6,tv_textview7;
	private String propertyid="",policeid="",producerid="";
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_addgpsdevice, null);
		initView();
		return rootView;
	}

	private void initView() {
		// TODO Auto-generated method stub
		((TextView) rootView.findViewById(R.id.tv_title)).setText(R.string.device_buy);
		rootView.findViewById(tv_next).setOnClickListener(listener);
		iv_gpsdevice = ((ImageView) rootView.findViewById(R.id.iv_gpsdevice));
		//iv_gpsdevice.setOnClickListener(listener);
		iv_combo = ((ImageView) rootView.findViewById(R.id.iv_combo));
		tv_comboprice = ((TextView) rootView.findViewById(R.id.tv_comboprice));
		tv_gpsprice = ((TextView) rootView.findViewById(R.id.tv_gpsprice));
		tv_allprice = ((TextView) rootView.findViewById(R.id.tv_allprice));
		tv_comboprice.setText(comboprice+"元/年");
		tv_gpsprice.setText(gpsprice+"元");
		tv_allprice.setText((comboprice+gpsprice)+"元");

		ll_linear5 = rootView.findViewById(R.id.ll_linear5);
		ll_linear6 = rootView.findViewById(R.id.ll_linear6);
		ll_linear7 = rootView.findViewById(R.id.ll_linear7);
		ll_linear5.setOnClickListener(listener);
		ll_linear6.setOnClickListener(listener);
		ll_linear7.setOnClickListener(listener);
		tv_textview5 = ((TextView) rootView.findViewById(R.id.tv_textview5));
		tv_textview6 = ((TextView) rootView.findViewById(R.id.tv_textview6));
		tv_textview7 = ((TextView) rootView.findViewById(R.id.tv_textview7));
	}

    public static AddGpsDevice newInstance() {
        AddGpsDevice fragment = new AddGpsDevice();
        return fragment;
    }

	private View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()){
				case tv_next:
					((SonActivity) getActivity()).addFragment(Pay.newInstance());
					break;
				case R.id.iv_gpsdevice:
					if(((String) iv_gpsdevice.getTag()).equals("true")){
						iv_gpsdevice.setTag("false");
						iv_gpsdevice.setImageResource(R.mipmap.icon_device_unselect);
						iv_combo.setTag("false");
						iv_combo.setImageResource(R.mipmap.icon_device_unselect);
						tv_allprice.setText("0元");
					}else{
						iv_gpsdevice.setTag("true");
						iv_gpsdevice.setImageResource(R.mipmap.icon_device_select);
						iv_combo.setTag("true");
						iv_combo.setImageResource(R.mipmap.icon_device_select);
						tv_allprice.setText((comboprice+gpsprice)+"元");
					}
					break;
				case R.id.ll_linear5:
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							propertyid = id;
							tv_textview5.setText(item);
						}
					},"5",""),true);
					break;
				case R.id.ll_linear6:
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							policeid = id;
							tv_textview6.setText(item);
						}
					},"6",""),true);
					break;
				case R.id.ll_linear7:
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							producerid = id;
							tv_textview7.setText(item);
						}
					},"7",""),true);
					break;
				default:
					break;
			}
		}
	};

	@Override
	public boolean onBackPressed() {
		return false;
	}
	
}
